/*
 * =====================================================================================
 *
 *       Filename:  LinkedStack.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  11/09/2012 02:29:44 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Kjeldahl (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include "LinkedStack.h"
LinkedStack * initLinkedStack(){
	Stackdata *sd=createElm();
	LinkedStack *S ;
	S=malloc(sizeof(LinkedStack));
	S->top=sd;
	S->length=-1;
	return S;
}
Stackdata * createElm(){

	Stackdata *sd;
	sd=malloc(sizeof(Stackdata));
	sd->data=malloc(sizeof(elmType)*SIZE);
	return sd;

}
void  emptyLinkedStack(LinkedStack *S){

	for(;S->length > -1;S->length--){
		free(S->top->data);
		free(S->top);
	}
	S->length=-1;

}
void destroyLinkedStack(LinkedStack *S){
	emptyLinkedStack(S);
	free(S);

}

elmType *getTop(LinkedStack *S){
	if(!isempty(S)){
	return S->top->data;
	}else{
	printf("Stack is empty\n");
	
	}
}
bool isempty(LinkedStack *S){
	return S->length==-1?true:false;
}

int getLength(LinkedStack *S){
	return S->length+1;
}
void showLinkedStack(LinkedStack *S){
	printf("Top\n");
	if(!isempty(S)){
	for(;S->length>-1;S->length--,S->top=S->top->next){
		printf("%x\n",S->top);
	}
	}else{
	printf("The Stack is empty\n")
	}
	printf("Bottom\n");
}
void push(LinkedStack *S,elmType *value){
	Stackdata *sd=createElm();
	sd->data=value;
	sd->next=S->top->next;
	S->length++;

	
}
elmType * pop(LinkedStack *S){
	if(!isempty(S)){
		printf("The Stack is empty\n");
	}else{
		elmType *data=S->top;
		S->length--;
		Stackdata *sd=S->top;
		S->top=S->top->next;//leak :Notice
		free(sd);
		return data;
	}
}



